home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODF-Interest Archive / May 96 / Re Menu Questions < prev    next >
Encoding:
Internet Message Format  |  1996-12-03  |  2.3 KB  |  [TEXT/ttxt]

  1. Subject:     Re: Menu Questions
  2. Sent:        5/15/96 11:35 AM
  3. Received:    5/17/96 9:02 AM
  4. From:        Mary Boetcher, Mary_Boetcher@quickmail.apple.com
  5. Reply-To:    ODF-Interest@CILabs.ORG
  6. To:          OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
  7.  
  8.         Reply to:   RE>Menu Questions
  9.  
  10. >> Once I have the menu created, I want to use the menu item text to tell me
  11. >> which font to set when one is chosen from the menu. How can I get the item
  12. >> text of the selected item in my part's DoMenu method?
  13. --------
  14.  
  15. Here is some code from my test part that creates and manages a font menu. You
  16. should define a range of command numbers to represent the font menu items.
  17.  
  18. void AddFontsToMenu(Environment* ev, FW_CPullDownMenu* menu)
  19. {
  20.     short count = 0;
  21.     FW_CFontIterator fontIter;
  22.     FW_CString fontName;
  23.     ODCommandID commandID = cFirstFontCommand;
  24.     for (fontName = fontIter.First(); fontIter.IsNotComplete(); fontName =
  25. fontIter.Next())
  26.     {
  27.         menu->AppendTextItem(ev, fontName, commandID+count);
  28.         count++;
  29.     }
  30.     gFontCount = count;
  31. }
  32.  
  33. FW_Boolean CMyEditView::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  34.                                       FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  35. {
  36.     if (hasMenuFocus)
  37.     {
  38.         //-- Enable all items in the Font menu
  39.         ODCommandID c = cFirstFontCommand;
  40.         for (short i=0; i < gFontCount; c++, i++)
  41.             menuBar->EnableAndCheckCommand(ev, c, true, false);
  42.  
  43.         //-- Put a check in front of the current font
  44.         c = GetCurrentFontCmd(ev, menuBar);
  45.         if (c != 0)
  46.             menuBar->CheckCommand(ev, c, true);
  47.     }
  48.     
  49.     return FW_CEditView::DoAdjustMenus(ev, menuBar, hasMenuFocus, isRoot);
  50. }
  51.  
  52. ODCommandID CMyEditView::GetCurrentFontCmd(Environment* ev, FW_CMenuBar*
  53. menuBar)
  54. {
  55.     ODCommandID result = 0;
  56.  
  57.     ODCommandID c = cFirstFontCommand;
  58.     FW_CString fontName;
  59.     for (short i=0; i < gFontCount; i++, c++)
  60.     {
  61.         menuBar->GetItemString(ev, c, fontName);
  62.         if (fontName == fFontName)
  63.         {
  64.             result = c;
  65.             break;
  66.         }
  67.  
  68.     return result;
  69.     }
  70.  
  71.     return result;    // could be 0
  72. }
  73.  
  74. FW_Boolean CMyEditView::DoMenu(Environment* ev, const FW_CMenuEvent&
  75. theMenuEvent) // Override
  76. {
  77.     FW_Boolean menuHandled = true;
  78.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  79.     
  80.     if (cFirstFontCommand <= id && id < cFirstFontCommand+gFontCount)
  81.     {
  82.         this->CommandToString(ev, id, fFontName);
  83.         this->DoSetFont(ev);
  84.         return menuHandled;
  85.     }
  86.     ...
  87. }
  88.  
  89. Mary Boetcher
  90. ODF Person
  91.